#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2016-11-06 17:38:31
# @Author  : guoben (guoben.ly@qq.com)
# @Link    : https://git.oschina.net/guoben

import cv2
import os

SOURCE_PATH = '../source/'
PICTURE_SUFFIX = ['jpeg', 'jpg', 'bmp', 'png', 'gif', 'tiff']


def is_picture(name):
    suffix = os.path.splitext(name)[1][1:]
    if suffix in PICTURE_SUFFIX:
        return True
    else:
        return False


def get_picture_list():
    dir1 = os.listdir(SOURCE_PATH)
    img_list = [SOURCE_PATH + i for i in dir1 if is_picture(i)]
    return img_list


if __name__ == "__main__":
    pic_list = get_picture_list()
    print pic_list
    img = cv2.imread(pic_list[0])
    if img is None:
        print "img do not exist!"
        exit(0)
    cv2.imshow('baby', img)
    cv2.waitKey(0) & 0xff
    cv2.destroyAllWindows()
